function [ann_sale ann_price ann_purchase ann_rating] = annual(num_firm,sample_sale,sample_price_origin,sample_purchase,sample_imp_ave)
% calculate moment
for l = 1:num_firm
        month_imp_reshape = reshape(sample_imp_ave(l,1:end)',48/4, 2*4);
        month_sale_reshape = reshape(sample_sale(l,1:end)',48/4, 2*4);
        month_price_reshape = reshape(sample_price_origin(l,:)',48/4,2*4);
        month_price_reshape(month_price_reshape==0) = nan;
        nan_sum = sum(isnan(month_sale_reshape),1); % firm exist indicator at month level
        month_sale_sum = nansum(month_sale_reshape,1);
        month_sale_sum(find(nan_sum==48/4)) = nan;
        month_imp_reshape(find(nan_sum==48/4))=nan;
        month_sale(l,:) = month_sale_sum; % num_firm * 4
        month_price_sum = month_price_reshape(48/4,:);
        month_sale_sum(find(month_sale_sum==0))=month_price_reshape(48/4,find(month_sale_sum==0));
        month_sale_calp(l,:) = month_sale_sum;
        month_purchase_sum = nansum(reshape(sample_purchase(l,1:end)',48/4, 2*4));
        month_purchase_sum(find(nan_sum==48/4)) = nan;
        month_purchase_true(l,:) = month_purchase_sum;
        month_purchase_sum(find(month_purchase_sum==0)) = 1;
        month_purchase(l,:) = month_purchase_sum; % num_firm * 4
end
   ann_purchase = month_purchase_true;
   ann_rating = month_imp_reshape;
    ann_sale = month_sale;
    ann_price = month_sale_calp./month_purchase;
%    ann_price(find(sum_sale==0),:) = nan;
%    ann_price = fillin(ann_price);
%    dlmwrite('ann_price.txt',log(ann_price));
 %   dlmwrite('ann_sale.txt',ann_sale);
end